﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DBBase;
using ZedGraph;

namespace Business
{
    public partial class quxian : DevExpress.XtraEditors.XtraForm
    {
        //public quxian()
        //{
        //    InitializeComponent();
        //}
        public int iliushuihao;
        public int igk;
        public static string hphm;
        public quxian(int idet, int igongkuan, string shphm)
        {
            InitializeComponent();
            iliushuihao = idet;
            igk = igongkuan;
            hphm = shphm;
            // getdate(iliushuihao, igk);


        }
        public void getdate(int idet, int igongkuang)
        {
            string sSQL = "";
            string sgongkuan = "5025";
            if (igongkuang == 5025)
            {
                sSQL = string.Format("SELECT * FROM GuoCheng25 WHERE DETECT_ID={0}", idet);
            }
            else if (igongkuang == 2540)
            {
                sSQL = string.Format("SELECT * FROM GuoCheng40 WHERE DETECT_ID={0}", idet);
                sgongkuan = "2540";
            }
            Query objquery = new Query();
            DataTable dt = objquery.GetTable(sSQL);
            if (dt.Rows.Count > 0)
            {
                string s1 = "";
                string s2 = "";
                string s3 = "";
                string s4 = "";
                string s5 = "";
                string s6 = "";
                string s7 = "";
                string s8 = "";
                string s9 = "";

                s1 = dt.Rows[0]["GC_HC"].ToString().Trim();
                s2 = dt.Rows[0]["GC_CO"].ToString().Trim();
                s3 = dt.Rows[0]["GC_NO"].ToString().Trim();
                s4 = dt.Rows[0]["GC_CO2"].ToString().Trim();
                s5 = dt.Rows[0]["GC_O2"].ToString().Trim();
                s6 = dt.Rows[0]["GC_Speed"].ToString().Trim();
                s7 = dt.Rows[0]["GC_DF"].ToString().Trim();
                s8 = dt.Rows[0]["GC_KH"].ToString().Trim();
                s9 = dt.Rows[0]["GC_PW"].ToString().Trim();

                WriteGraphEX(zg, hphm, sgongkuan, s1.Split(new char[] { ',' }), s2.Split(new char[] { ',' }), s3.Split(new char[] { ',' }), s4.Split(new char[] { ',' }), s5.Split(new char[] { ',' }), s6.Split(new char[] { ',' }), s7.Split(new char[] { ',' }), s8.Split(new char[] { ',' }), s9.Split(new char[] { ',' }));

            }
        }
        public void WriteGraphEX(ZedGraphControl zgc, string shphm, string sgongkuang, string[] s1, string[] s2, string[] s3, string[] s4, string[] s5, string[] s6, string[] s7, string[] s8, string[] s9)
        {
            GraphPane myPane = zgc.GraphPane;
            myPane.Fill = new Fill(Color.White, Color.Aqua, 45.0f);
            myPane.Legend.Fill = new Fill(Color.Gainsboro);
            myPane.Chart.Fill = new Fill(Color.Gainsboro);

            myPane.CurveList.Clear();

            // Set the titles and axis labels 设置标题、坐标轴标签


            myPane.Title.Text = string.Format("{0}简易稳态法{1}工况过程数据", hphm, sgongkuang);

            myPane.XAxis.Title.Text = "时间(s)";
            myPane.YAxis.Title.Text = "测量结果";

            myPane.YAxis.MajorGrid.IsVisible = false;
            myPane.YAxis.MinorTic.Size = 0f;

            double mmin, mmax;
            mmin = Math.Pow(10, -2);
            mmax = Math.Pow(10, 4);

            myPane.YAxis.Scale.Min = mmin;
            myPane.YAxis.Scale.Max = mmax;
            string sss1 = string.Format("{0}", Math.Pow(10, -2));
            string ssss2 = string.Format("{0}", Math.Pow(10, -1));
            string sss3 = string.Format("{0}", Math.Pow(10, 0));
            string sss4 = string.Format("{0}", Math.Pow(10, 1));
            string sss5 = string.Format("{0}", Math.Pow(10, 2));
            string sss6 = string.Format("{0}", Math.Pow(10, 3));
            string sss7 = string.Format("{0}", Math.Pow(10, 4));


            string[] labels = { sss1, ssss2, sss3, sss4, sss5, sss6, sss7 };
            myPane.YAxis.Scale.TextLabels = labels;//Y轴名称列表
            myPane.YAxis.Type = AxisType.Log;
            myPane.YAxis.Scale.MajorStep = 1;



            zgc.IsShowPointValues = true;//数据节点



            string ss0 = string.Format("{0}", "HC");
            string ss1 = string.Format("{0}", "CO");
            string ss2 = string.Format("{0}", "NO");
            string ss3 = string.Format("{0}", "CO2");
            string ss4 = string.Format("{0}", "O2");
            string ss5 = string.Format("{0}", "Speed");
            string ss6 = string.Format("{0}", "DF");
            string ss7 = string.Format("{0}", "KH");
            string ss8 = string.Format("{0}", "PW");

            // Make up some data points from the Sine function 弥补一些数据点的正弦函数
            PointPairList list0 = new PointPairList();
            PointPairList list1 = new PointPairList();
            PointPairList list2 = new PointPairList();
            PointPairList list3 = new PointPairList();
            PointPairList list4 = new PointPairList();
            PointPairList list5 = new PointPairList();
            PointPairList list6 = new PointPairList();
            PointPairList list7 = new PointPairList();
            PointPairList list8 = new PointPairList();

            // Generate a blue curve with circle symbols, and "My Curve 2" in the legend 生成一个与圆符号蓝色曲线，和“我的曲线2”的传说
            LineItem myCurve0 = myPane.AddCurve(ss0, list0, Color.Blue,
                                    SymbolType.None);
            LineItem myCurve1 = myPane.AddCurve(ss1, list1, Color.Red,
                                    SymbolType.None);
            LineItem myCurve2 = myPane.AddCurve(ss2, list2, Color.Lime,
                                   SymbolType.None);
            LineItem myCurve3 = myPane.AddCurve(ss3, list3, Color.Fuchsia,
                                   SymbolType.None);
            LineItem myCurve4 = myPane.AddCurve(ss4, list4, Color.Yellow,
                                   SymbolType.None);
            LineItem myCurve5 = myPane.AddCurve(ss5, list5, Color.Orange,
                                   SymbolType.None);
            LineItem myCurve6 = myPane.AddCurve(ss6, list6, Color.Black,
                                   SymbolType.None);
            LineItem myCurve7 = myPane.AddCurve(ss7, list7, Color.Aqua,
                                   SymbolType.None);

            LineItem myCurve8 = myPane.AddCurve(ss8, list8, Color.Green,
                                   SymbolType.None);

            myCurve0.Line.Width = 1.7F;
            myCurve1.Line.Width = 1.7F;
            myCurve2.Line.Width = 1.7F;
            myCurve3.Line.Width = 1.7F;
            myCurve4.Line.Width = 1.7F;
            myCurve5.Line.Width = 1.7F;
            myCurve6.Line.Width = 1.7F;
            myCurve7.Line.Width = 1.7F;
            myCurve8.Line.Width = 1.7F;
           

            double dval = 0;

            if (!(s1[0] == ""))
            {
                for (int i = 0; i < s1.Length; i++)
                {
                    double.TryParse(s1[i], out dval);

                    list0.Add((i + 1), dval);
                }
            }

            //2
            if (!(s2[0] == ""))
            {
                for (int i = 0; i < s2.Length; i++)
                {
                    double.TryParse(s2[i], out dval);

                    list1.Add((i + 1), dval);
                }
            }
            //3
            if (!(s3[0] == ""))
            {
                for (int i = 0; i < s3.Length; i++)
                {

                    double.TryParse(s3[i], out dval);

                    list2.Add((i + 1), dval);
                }
            }
            //4
            if (!(s4[0] == ""))
            {
                for (int i = 0; i < s4.Length; i++)
                {

                    double.TryParse(s4[i], out dval);

                    list3.Add((i + 1), dval);
                }
            }
            //5
            if (!(s5[0] == ""))
            {
                for (int i = 0; i < s5.Length; i++)
                {

                    double.TryParse(s5[i], out dval);

                    list4.Add((i + 1), dval);
                }
            }
            //6
            if (!(s6[0] == ""))
            {
                for (int i = 0; i < s6.Length; i++)
                {

                    double.TryParse(s6[i], out dval);

                    list5.Add((i + 1), dval);
                }
            }
            //7
            if (!(s7[0] == ""))
            {
                for (int i = 0; i < s7.Length; i++)
                {

                    double.TryParse(s7[i], out dval);

                    list6.Add((i + 1), dval);
                }
            }
            //8
            if (!(s8[0] == ""))
            {
                for (int i = 0; i < s8.Length; i++)
                {

                    double.TryParse(s8[i], out dval);

                    list7.Add((i + 1), dval);
                }
            }
            //9
            if (!(s9[0] == ""))
            {
                for (int i = 0; i < s9.Length; i++)
                {

                    double.TryParse(s9[i], out dval);

                    list8.Add((i + 1), dval);
                }
            }

            zgc.AxisChange();
            zgc.Invalidate();
        }

        private void quxian_Load(object sender, EventArgs e)
        {
            getdate(iliushuihao, igk);
        }
    }
}